{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "dpath='./data/'\n",
    "train = dpath+'train.csv'              # path to training file\n",
    "test = dpath+'test.csv'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "train_df=pd.read_csv(train,nrows=10000)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 10000 entries, 0 to 9999\n",
      "Data columns (total 24 columns):\n",
      "id                  10000 non-null uint64\n",
      "click               10000 non-null int64\n",
      "hour                10000 non-null int64\n",
      "C1                  10000 non-null int64\n",
      "banner_pos          10000 non-null int64\n",
      "site_id             10000 non-null object\n",
      "site_domain         10000 non-null object\n",
      "site_category       10000 non-null object\n",
      "app_id              10000 non-null object\n",
      "app_domain          10000 non-null object\n",
      "app_category        10000 non-null object\n",
      "device_id           10000 non-null object\n",
      "device_ip           10000 non-null object\n",
      "device_model        10000 non-null object\n",
      "device_type         10000 non-null int64\n",
      "device_conn_type    10000 non-null int64\n",
      "C14                 10000 non-null int64\n",
      "C15                 10000 non-null int64\n",
      "C16                 10000 non-null int64\n",
      "C17                 10000 non-null int64\n",
      "C18                 10000 non-null int64\n",
      "C19                 10000 non-null int64\n",
      "C20                 10000 non-null int64\n",
      "C21                 10000 non-null int64\n",
      "dtypes: int64(14), object(9), uint64(1)\n",
      "memory usage: 1.8+ MB\n"
     ]
    }
   ],
   "source": [
    "train_df.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "train_df['date']=train_df['hour'].apply(lambda x:int((x%10000)-(x%100))/100)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "train_df['time_period']=train_df['hour'].apply(lambda x:x%100)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "train_df['weekday']=train_df['date'].apply(lambda x:0 if x==25 or x==26 else 1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "train_df['C15_C16']=train_df['C15']-train_df['C16']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "train_df['site_category']=train_df['site_category'].apply(lambda x:'others' if x not in ['50e219e0','f028772b','28905ebd','3e814130']else x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
